package solution.leetcode;

import java.util.HashMap;

public class MapTest {
    public static void main(String[] args) {
        String s = "aabcda";
        int left = 0; //左指针
        int max = 0;
        HashMap<Character, Integer> map = new HashMap<>();
        for (int i = 0 ; i < s.length() ; i++){
            if (map.containsKey(s.charAt(i))){
                left = Math.max(i , map.get(s.charAt(i)) + 1);
            }
            map.put(s.charAt(i),i);
            max = Math.max(max,i-left+1);
        }
        System.out.println(max);
    }
}
